package org.cid54.bukkit.command;

import org.cid54.bukkit.command.util.PlayerCommand;
import org.bukkit.event.player.PlayerChatEvent;
import org.cid54.bukkit.Cid54PlayerListener;

/**
 *
 * @author Cid54
 */
public class GiveCommand implements PlayerCommand {

    public boolean execute(String command, PlayerChatEvent event, Cid54PlayerListener listener) {
        String[] commands = command.split(" ");

        int amount = 1;

        if (commands.length > 2) {
            amount = Integer.parseInt(commands[2]);
        }

        while (amount > 64) {

            if (event.getPlayer().performCommand("give " + event.getPlayer().getName() + " " + commands[1] + " " + 64)) {
                amount -= 64;
            }
        }
        event.getPlayer().performCommand("give " + event.getPlayer().getName() + " " + commands[1] + " " + amount);

        return true;

    }

    public String getCommand() {
        return "give";


    }

    public String getHelpText() {
        return "Gives items";

    }
}
